﻿
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;

using PowerCreator.LMS.DL.Project.Entity;
using PowerCreator.LMS.Web.DL.Project;
using PowerCreator.LMS.Common.Script;
public partial class sysadmin_DL_Project_ManageUserClassTask : PowerCreator.LMS.Web.Base.WebBasePage
{
    protected string ClassName = string.Empty;
    protected string CourseNum = string.Empty;
    private string CourseID = string.Empty;
    PowerCreator.LMS.ViewQuery.ViewQuery obj = new PowerCreator.LMS.ViewQuery.ViewQuery();
    VOTOClassTasks voClassTask = new VOTOClassTasks();
    TOClassTasks objClassTask = new TOClassTasks();
    private VOTOClass voClass = new VOTOClass();
    TOClass objClass = new TOClass();
    //TOUserOfClass objClassUser = new TOUserOfClass();

    protected void Page_Load(object sender, EventArgs e)
    {
        InitPage();
        int CID = 0;
        if (Request.QueryString["CID"] != null)
        {
            CID = int.Parse(Request.QueryString["CID"].ToString());
            ViewState["CID"] = CID.ToString();
            voClass = objClass.Load(CID);
            ClassName = voClass.Name;
            BinderPG(voClass);
        }
    } 

    protected override void InitPage()
    {
        base.InitPage();
    }



    private void BinderPG(VOTOClass vo)
    {
        VOTOCourseList voCourselist = new VOTOCourseList();
        TOCourseList objCourselist = new TOCourseList();
        voCourselist = objCourselist.Load(vo.ClassCourseListID);
        string CourseIDsList = voCourselist.CourseID;
        string[] courseid = CourseIDsList.Split(',');
        CourseNum = courseid.Length.ToString();
        string courseidlist = string.Empty;
        for (int i = 0; i < courseid.Length; i++)
        {
            string[] par = courseid[i].Split('#');
            if (par.Length == 2)
            {
                if (courseidlist.Length > 0)
                    courseidlist += ",";
                courseidlist += par[0];
            }
        }
        if (courseidlist.Length == 0)
            courseidlist = "0";

        string search = "SELECT TO_Course.Course_Id, TO_Course.CourseName, TO_ClassTasks.ClassTasks_Id, TO_ClassTasks.ClassID, TO_ClassTasks.TasksTitle, TO_ClassTasks.EndDate, TO_ClassTasks.Broswer,TO_ClassTasks.CreatDate, TO_ClassTasks.SetTop, TO_ClassTasks.SetHighLight FROM TO_ClassTasks,TO_Course where TO_ClassTasks.Course_ID = TO_Course.Course_Id  and TO_ClassTasks.ClassID=" + ViewState["CID"].ToString();
        DataTable dt = obj.Query(search);


        search = "SELECT Course_Id, CourseName FROM TO_Course where Course_Id in (" + courseidlist + ") and Course_Id not in (select Course_ID from TO_ClassTasks where ClassID=" + ViewState["CID"].ToString() + ")";
        DataTable dt01 = obj.Query(search);

        dt01.Columns.Add("ClassTasks_Id");
        dt01.Columns.Add("ClassID");
        dt01.Columns.Add("TasksTitle");
        dt01.Columns.Add("EndDate");
        dt01.Columns.Add("Broswer");
        dt01.Columns.Add("CreatDate");
        dt01.Columns.Add("SetTop");
        dt01.Columns.Add("SetHighLight");

        for (int j = 0; j < dt01.Rows.Count; j++)
        {
            dt01.Rows[j]["ClassTasks_Id"] = "0";
            dt01.Rows[j]["ClassID"] = int.Parse(Request.QueryString["CID"].ToString());
            dt01.Rows[j]["TasksTitle"] = "--";
            dt01.Rows[j]["EndDate"] = DateTime.Now;
            dt01.Rows[j]["Broswer"] = false;
            dt01.Rows[j]["SetTop"] = false;
            dt01.Rows[j]["SetHighLight"] = false;
            dt.Rows.Add(dt01.Rows[j]["Course_Id"], dt01.Rows[j]["CourseName"], dt01.Rows[j]["ClassTasks_Id"], dt01.Rows[j]["ClassID"], dt01.Rows[j]["TasksTitle"], dt01.Rows[j]["EndDate"], dt01.Rows[j]["Broswer"], dt01.Rows[j]["CreatDate"], dt01.Rows[j]["SetTop"], dt01.Rows[j]["SetHighLight"], dt01.Rows[j]["rowstat"]);
            
        }

        search = "SELECT  Course_ID,ClassTasks_Id, ClassID, TasksTitle, EndDate, Broswer,CreatDate, SetTop,SetHighLight FROM TO_ClassTasks where Course_ID = 0  and ClassID=" + ViewState["CID"].ToString();
        DataTable dt03 = obj.Query(search);
        dt03.Columns.Add("CourseName");


        for (int k = 0; k < dt03.Rows.Count; k++)
        {
            dt03.Rows[k]["CourseName"] = "--";

            dt.Rows.Add(dt03.Rows[k]["Course_Id"], dt03.Rows[k]["CourseName"], dt03.Rows[k]["ClassTasks_Id"], dt03.Rows[k]["ClassID"], dt03.Rows[k]["TasksTitle"], dt03.Rows[k]["EndDate"], dt03.Rows[k]["Broswer"], dt03.Rows[k]["CreatDate"], dt03.Rows[k]["SetTop"], dt03.Rows[k]["SetHighLight"], dt03.Rows[k]["rowstat"]);


        }


        rptNew.DataSource = dt;
        rptNew.DataBind();
    }
    protected void rpt_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
        {
            LinkButton lnkbtn_look = (LinkButton)e.Item.FindControl("lnkbtn_look");
            Label lab_ID = (Label)e.Item.FindControl("lab_ID");
            //lnkbtn_del.Attributes.Add("onClick", "javascript:return confirm('确定删除此记录？');");

            if (lab_ID.Text == "0")
            {
                lnkbtn_look.Enabled = false;
            }
        }
    }

  
    protected void rptNew_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        VOTOClassTasks vo = new VOTOClassTasks();
        Label lbl_msg = (Label)e.Item.FindControl("lbl_msg");
        Label lab_CourseID = (Label)e.Item.FindControl("lab_CourseID");

        if (e.CommandName.ToLower() == "look")
        {
            string url = "ManageUserClassTaskList.aspx?CTID=" + e.CommandArgument.ToString() + "&CourseID="+lab_CourseID.Text.Trim()+"&CID=" + ViewState["CID"].ToString();
            Script.RedirectURL(url);

        }
        else if (e.CommandName.ToLower() == "looknofinish")
        {
            string url = "ManageNofinishClassTaskUserList.aspx?CTID=" + e.CommandArgument.ToString() + "&CourseID=" + lab_CourseID.Text.Trim() + "&CID=" + ViewState["CID"].ToString();
            Script.RedirectURL(url);

        }
       
    }
 
}